package com.qinhao.loveCrowdFunding.utils;


import java.util.Calendar;

public class RandomOrderUtil {

    public String generateOid() {
        String oid;
        //17位订单号
        StringBuilder sbNumber = new StringBuilder();
        Calendar now = Calendar.getInstance();
        System.out.println("秒：" + now.get(Calendar.SECOND));
        sbNumber.append(now.get(Calendar.YEAR));//4
        sbNumber.append((now.get(Calendar.MONTH) + 1)+"".length()== 1 ? "0" + (now.get(Calendar.MONTH) + 1)+"" : (now.get(Calendar.MONTH) + 1)+"");//2
        sbNumber.append(now.get(Calendar.DAY_OF_MONTH)+"".length() == 1 ? "0" + now.get(Calendar.DAY_OF_MONTH)+"" : now.get(Calendar.DAY_OF_MONTH)+"");//2
        sbNumber.append(now.get(Calendar.HOUR_OF_DAY)+"".length() == 1 ? "0" + now.get(Calendar.HOUR_OF_DAY)+"" : now.get(Calendar.HOUR_OF_DAY)+"");//2
        sbNumber.append(now.get(Calendar.MINUTE)+"".length() == 1 ? "0" + now.get(Calendar.MINUTE)+"" : now.get(Calendar.MINUTE)+"");//2
        sbNumber.append(now.get(Calendar.SECOND)+"".length() == 1 ? "0" + now.get(Calendar.SECOND)+"" : now.get(Calendar.SECOND)+"");//2
        if (now.get(Calendar.MILLISECOND)+"".length() == 1) {
            sbNumber.append("00" + now.get(Calendar.MILLISECOND));
        } else if (now.get(Calendar.MILLISECOND)+"".length() == 2) {
            sbNumber.append("0" + now.get(Calendar.MILLISECOND)+"");
        } else {
            sbNumber.append(now.get(Calendar.MILLISECOND)+"");
        }
        //返回不重复的字串
        oid = sbNumber.toString();
        return oid;
    }
}
